package com.crm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.SysRewards;
import com.crm.service.SysRewardsService;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

@Controller
@RequestMapping("/reward")
public class SysRewardsController {
	
	@Autowired
	private SysRewardsService sysRewardsService;
	
	@RequestMapping("/index")
	public String index(Page<SysRewards> page, SysRewards t, ModelMap map){
		
		return "sysconf/rewards";
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public void getAll(HttpServletResponse response,HttpServletRequest request, Page<SysRewards> page, SysRewards t){
		
		Page<SysRewards> list = (Page<SysRewards>) sysRewardsService.selectAll(page, t);
		
		ResponseUtil.resultPage(response,request,list);
	}
	
	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(SysRewards record){
		
		Map<String, Object> map = new HashMap<>();
		
		sysRewardsService.insert(record);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	
	@RequestMapping("/deleteRecord")
	@ResponseBody
	public Map<String, Object> deleteRecord(SysRewards record){
		
		Map<String, Object> map = new HashMap<>();
		
		record.setDeleteMark(0);
		sysRewardsService.updateByPrimaryKey(record);
		
		map.put("status", "success");
		map.put("msg", "删除成功！");
		
		return map;
	}
	
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Map<String, Object> updateRecord(SysRewards record){
		
		Map<String, Object> map = new HashMap<>();
		
		sysRewardsService.updateByPrimaryKey(record);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
	
}
  
